package ar.edu.uba.fi.jmit.monitorengine.parser;

import java.util.List;

import ar.edu.uba.fi.jmit.monitorengine.MonitorEngineTestCase;
import ar.edu.uba.fi.jmit.monitorengine.core.MonitorDescriptor;
import ar.edu.uba.fi.jmit.monitorengine.core.MonitorLifeType;

public class XMLConfigurationMonitorEngineParserTestCase extends MonitorEngineTestCase {
	
	private static String CONFIGURATION_FILES_PATH = "src/test/resources/testParser";
	
	public void testManyConfigurations() {
		
		List<MonitorDescriptor> monitorDescriptor = null;
		try {
			monitorDescriptor = XMLConfigurationMonitorEngineParser.parse(CONFIGURATION_FILES_PATH + "/ConfMETest.conf.xml");
		} catch (Exception e) {
			fail(e);
		}
		assertEquals(monitorDescriptor.size(), 4);
		assertEquals(monitorDescriptor.get(0).getClazz(),"ar.edu.uba.fi.jmit.monitorengine.mock.MockMonitor1");
		assertEquals(monitorDescriptor.get(0).getLifeType(),MonitorLifeType.APPLICATION);
		assertEquals(monitorDescriptor.get(0).match("InvocationCounter"), true);
		assertEquals(monitorDescriptor.get(0).match("ObjectCounter"), false);
		assertEquals(monitorDescriptor.get(0).match("FieldValue"), false);
		
		assertEquals(monitorDescriptor.get(1).getClazz(),"ar.edu.uba.fi.jmit.monitorengine.mock.MockMonitor2");
		assertEquals(monitorDescriptor.get(1).getLifeType(),MonitorLifeType.SINGLETON);
		assertEquals(monitorDescriptor.get(1).match("ObjectCounter"), true);
		assertEquals(monitorDescriptor.get(1).match("InvocationCounter"), false);
		assertEquals(monitorDescriptor.get(1).match("FieldValue"), false);
		
		assertEquals(monitorDescriptor.get(2).getClazz(),"ar.edu.uba.fi.jmit.monitorengine.mock.MockMonitor3");
		assertEquals(monitorDescriptor.get(2).getLifeType(),MonitorLifeType.MONITOR_NAME);
		assertEquals(monitorDescriptor.get(2).match("FieldValue"), true);
		assertEquals(monitorDescriptor.get(2).match("InvocationCounter"), false);
		assertEquals(monitorDescriptor.get(2).match("ObjectCounter"), false);
		
		assertEquals(monitorDescriptor.get(3).getClazz(),"ar.edu.uba.fi.jmit.monitorengine.mock.MockMonitor4");
		assertEquals(monitorDescriptor.get(3).getLifeType(),MonitorLifeType.MONITOR_NAME);
		assertEquals(monitorDescriptor.get(3).match("FieldValue"), false);
		assertEquals(monitorDescriptor.get(3).match("InvocationCounter"), false);
		assertEquals(monitorDescriptor.get(3).match("ObjectCounter"), false);
		assertEquals(monitorDescriptor.get(3).match("AverageMethodTime"), true);
	}

}
